<?php

/**
 * 通用 可视化菜单验证
 * Trait AuthTrait
 */
use Think\Auth;
trait MenuAuthTrait {
    public function run(&$params)
    {
        $userDao = D('User');
        $authDao = new Auth();
        $me = $userDao->getMe();
        if ($userDao->isAdministrator($me['id'])) {
            return true;
        }
        foreach ($params as $key => &$row) {
            if (!$authDao->check($row['name'], $me['id'], array('exp', '<> ""'), '')) {
                unset($params[$key]);
            }
            if($params[$key]['_child']) {
                $this->run($params[$key]['_child']);
            }
        }
    }
}